<!-- vbl -->
<template>
  <div>
    <!-- 面包屑,页面路径 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 显示卡片 -->
    <el-card>
      <!-- data 和渲染的数据数组(对象),绑定 border边框 stripe 条纹 -->
      <el-table :data="authorityList" border stripe>
        <!-- label -->
        <el-table-column type="index" label="序号" width="80">
        </el-table-column>

        <el-table-column prop="authName" label="权限名称">
        </el-table-column>

        <el-table-column prop="path" label="路径">
        </el-table-column>

        <el-table-column prop="level" label="等级">
          <!-- 作用域插槽 -->
          <template slot-scope="scope">
            <el-tag v-if="scope.row.level === '0'">一级</el-tag>
            <el-tag v-else-if="scope.row.level === '1'" type="success">二级</el-tag>
            <el-tag v-else type="warning">三级</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
// request包装过的axios对象
import request from '@/utils/request';

export default {
  data () {
    return {
      authorityList: []
    }
  },
  // 需要使用生命周期函数
  mounted () {
    // 获取列表数据
    this.getRightList()
  },
  methods: {
    // 获取权限列表
    async getRightList () {
      const { data: { data, meta } } = await request({
        url: "/rights/list",
        method: "GET"
      })
      // 获取失败
      if (meta.status !== 200) {
        return this.$message.error('网络异常,稍后重试')
      }
      this.authorityList = data
      this.$message.success(meta.msg)
      // console.log(back);
    }
  }
}
</script>

<style lang="less" scoped>
.el-card {
  margin-top: 20px;
}
</style>
